<?php

use Faker\Factory as Faker;
use App\Models\CategoryStatistics;
use App\Repositories\CategoryStatisticsRepository;

trait MakeCategoryStatisticsTrait
{
    /**
     * Create fake instance of CategoryStatistics and save it in database
     *
     * @param array $categoryStatisticsFields
     * @return CategoryStatistics
     */
    public function makeCategoryStatistics($categoryStatisticsFields = [])
    {
        /** @var CategoryStatisticsRepository $categoryStatisticsRepo */
        $categoryStatisticsRepo = App::make(CategoryStatisticsRepository::class);
        $theme = $this->fakeCategoryStatisticsData($categoryStatisticsFields);
        return $categoryStatisticsRepo->create($theme);
    }

    /**
     * Get fake instance of CategoryStatistics
     *
     * @param array $categoryStatisticsFields
     * @return CategoryStatistics
     */
    public function fakeCategoryStatistics($categoryStatisticsFields = [])
    {
        return new CategoryStatistics($this->fakeCategoryStatisticsData($categoryStatisticsFields));
    }

    /**
     * Get fake data of CategoryStatistics
     *
     * @param array $postFields
     * @return array
     */
    public function fakeCategoryStatisticsData($categoryStatisticsFields = [])
    {
        $fake = Faker::create();

        return array_merge([
            'date' => $fake->word,
            'type' => $fake->randomDigitNotNull,
            'goods_count' => $fake->randomDigitNotNull,
            'goods_amount' => $fake->word,
            'goods_return_count' => $fake->randomDigitNotNull,
            'goods_return_amount' => $fake->word,
            'goods_return_rate' => $fake->word,
            'json' => $fake->text,
            'created_at' => $fake->word,
            'updated_at' => $fake->word
        ], $categoryStatisticsFields);
    }
}
